var over = false;

$(document).ready(function() {
	$.post("/toolbar", 
		{}, 
		function(data){ 
			if (data == 1)
				$("#presence").hide();
			else	
				$("#presence").html(data);
		}
	);
});

function appLeftHover(divE) {
	divE.style.backgroundColor  = '#fff'; 
}

function appLeftUnHover(divE) {
	divE.style.backgroundColor = ''; 
}

function miniblog_add_user_reply(username) {
	var content = $('#mess_content').val() +' @'+username+' ';
	$('#mess_content').val(content);
}

function miniblog_view_tool(id, isOwn) {
	if (isOwn != 1)
		$('#miniblog_reply_icon'+id).show();
	else
		$('#miniblog_del_icon'+id).show();

	if ($('#miniblog_is_favor'+id).val() == 0)		
		$('#miniblog_star_icon'+id).show();
}

function miniblog_hide_tool(id, isOwn) {
	if (isOwn != 1)
		$('#miniblog_reply_icon'+id).hide();
	else
		$('#miniblog_del_icon'+id).hide();
		
	if ($('#miniblog_is_favor'+id).val() == 0)
		$('#miniblog_star_icon'+id).hide();
}

function chars_left(e) {
	//Current character count

	var current = document.getElementById('mess_content').value.length+1;

	//How many left?
	var chars_left = 140 - current;

	if (chars_left < 0) chars_left = 0;
	
	//Over the limit or not?

	if(chars_left == 0) {
		//Over the limit

		over = true;
		//Time for a warning
		//alert('Nội dung quá dài');
	} else {

		//Reset

		over = false;

		//Clear any warnings

		//document.getElementById('warning').innerHTML = "";

	}

	//Display the number of chars left.
	document.getElementById('charleft').innerHTML = chars_left;

	if (e.keyCode == 13) { 
		updateMiniblog();
		return false;
	}
}
